#include "CardPanel.h"

#include <QMouseEvent>

CardPanel::CardPanel(QWidget *parent)
    : QWidget{parent}
{}

void CardPanel::setImage(const QPixmap &front, const QPixmap &back)
{
    m_front = front;
    m_back = back;
    setFixedSize(m_front.size());//设置窗口变成图片的大小
    update();//每次设置图片就重新绘制
}

QPixmap CardPanel::image()
{
    return m_front;
}

void CardPanel::setFrontSide(bool flag)
{
    m_isFront = flag;
}

bool CardPanel::frontSide()
{
    return m_isFront;
}

void CardPanel::setSelected(bool flag)
{
    m_isSelected = flag;
}

bool CardPanel::isSelected()
{
    return m_isSelected;
}

void CardPanel::setCard(const Card &card)
{
    m_card = card;
}

Card CardPanel::card()
{
    return m_card;
}

void CardPanel::setOwner(Player *player)
{
    m_owner = player;
}

Player *CardPanel::owner()
{
    return m_owner;
}

void CardPanel::clicked()
{
    emit cardSelected(Qt::LeftButton);
}

void CardPanel::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    if(m_isFront){
        painter.drawPixmap(rect(),m_front);
    }else{
        painter.drawPixmap(rect(),m_back);
    }
}

void CardPanel::mousePressEvent(QMouseEvent *event)
{
    emit cardSelected(event->button());
}
